package shili;



public class Block {
    public static void main(String[] args) {
        //BlockingQueue<Integer> q = new ArrayBlockingQueue<>(1000);
        MyBlockingQueue qq = new MyBlockingQueue(1000);
        //生产者线程
        Thread t1 = new Thread(()->{
            int i = 1;
            while(true){
                try {
                    qq.put(""+i);
                    System.out.println("生产元素"+i);
                    i++;
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
        //消费者线程
        Thread t2 = new Thread(()->{
            while(true){
                int i = 0;
                try {
                    i = Integer.parseInt(qq.take());
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("消费元素"+i);
            }
        });
        t1.start();
        t2.start();
    }

}
